Copy elements between two arrays.
The folowing function populates an array with some integer elements and then copies them to another array
C# .NET |
const string headerFmt = "\n{0,-45}{1}"; const string dataFmt = "{0,-12}{1,8} {2,-18}{3,21}{4}" ; // Display the properties of the TimeSpan parameter. static string ShowTimeSpanProperties( TimeSpan interval ) { string strRet = ""; string sNL = Environment.NewLine; strRet += String.Format( "{0,21}{1}", interval, sNL ); strRet += String.Format( dataFmt, "Days", interval.Days, "TotalDays", interval.TotalDays, sNL ); strRet += String.Format( dataFmt, "Hours", interval.Hours, "TotalHours", interval.TotalHours, sNL ); strRet += String.Format( dataFmt, "Minutes", interval.Minutes, "TotalMinutes", interval.TotalMinutes, sNL ); strRet += String.Format( dataFmt, "Seconds", interval.Seconds, "TotalSeconds", interval.TotalSeconds, sNL ); strRet += String.Format( dataFmt, "Milliseconds", interval.Milliseconds, "TotalMilliseconds", interval.TotalMilliseconds, sNL); strRet += String.Format( dataFmt, null, null, "Ticks", interval.Ticks, sNL ); return strRet; } public static String DoTest() { String strRet = ""; string sNL = Environment.NewLine; strRet += "This example of the TimeSpan class properties " + "generates the \nfollowing output. It " + "creates several TimeSpan objects and \ndisplays " + "the values of the TimeSpan properties for each."; // Create and display a TimeSpan value of 1 tick. strRet += String.Format( headerFmt, "TimeSpan( 1 )", sNL ); strRet += ShowTimeSpanProperties( new TimeSpan( 1 ) ); // Create a TimeSpan value with a large number of ticks. strRet += String.Format( headerFmt, "TimeSpan( 111222333444555 )", sNL ); strRet += ShowTimeSpanProperties( new TimeSpan( 111222333444555 ) ); // This TimeSpan has all fields specified. strRet += String.Format( headerFmt, "TimeSpan( 10, 20, 30, 40, 50 )", sNL ); strRet += ShowTimeSpanProperties( new TimeSpan( 10, 20, 30, 40, 50 ) ); // This TimeSpan has all fields overflowing. strRet += String.Format( headerFmt, "TimeSpan( 1111, 2222, 3333, 4444, 5555 )", sNL ); strRet += ShowTimeSpanProperties( new TimeSpan( 1111, 2222, 3333, 4444, 5555 ) ); // This TimeSpan is based on a number of days. strRet += String.Format( headerFmt, "FromDays( 20.84745602 )", sNL ); strRet += ShowTimeSpanProperties( TimeSpan.FromDays( 20.84745602 ) ); return strRet; } |
Blaze++ .NET |
// Display the properties of the TimeSpan parameter. static String ShowTimeSpanProperties( TimeSpan& interval ) { Double d = Double(interval.TotalDays); String s = d.ToString(); String strRet = ""; String sNL = Environment::NewLine; strRet += String::Format( "{0,21}{1}", interval, sNL ); strRet += String::Format( dataFmt, String("Days"), Int32(interval.Days), String("TotalDays"), Double(interval.TotalDays), sNL ); strRet += String::Format( dataFmt, String("Hours"), Int32(interval.Hours), String("TotalHours"), Double(interval.TotalHours), sNL ); strRet += String::Format( dataFmt, String("Minutes"), Int32(interval.Minutes), String("TotalMinutes"), Double(interval.TotalMinutes), sNL ); strRet += String::Format( dataFmt, String("Seconds"), Int32(interval.Seconds), String("TotalSeconds"), Double(interval.TotalSeconds), sNL ); strRet += String::Format( dataFmt, String("Milliseconds"), Int32(interval.Milliseconds), String("TotalMilliseconds"), Double(interval.TotalMilliseconds), sNL); strRet += String::Format( dataFmt, null, null, String("Ticks"), Int64(interval.Ticks), sNL ); return strRet; } static String DoTest() { String strRet = ""; String sNL = Environment::NewLine; strRet += ("This example of the TimeSpan class properties generates the \nfollowing output. It creates several TimeSpan objects and \ndisplays the values of the TimeSpan properties for each."); // Create and display a TimeSpan value of 1 tick. strRet += String::Format( headerFmt, "TimeSpan( 1 )", sNL ); strRet += ShowTimeSpanProperties(TimeSpan( 1 ) ); // Create a TimeSpan value with a large number of ticks. strRet += String::Format( headerFmt, "TimeSpan( 111222333444555 )", sNL ); strRet += ShowTimeSpanProperties( TimeSpan( 111222333444555 ) ); // This TimeSpan has all fields specified. strRet += String::Format( headerFmt, "TimeSpan( 10, 20, 30, 40, 50 )", sNL ); strRet += ShowTimeSpanProperties( TimeSpan( 10, 20, 30, 40, 50 ) ); // This TimeSpan has all fields overflowing. strRet += String::Format( headerFmt, "TimeSpan( 1111, 2222, 3333, 4444, 5555 )", sNL ); strRet += ShowTimeSpanProperties( TimeSpan( 1111, 2222, 3333, 4444, 5555 ) ); // This TimeSpan is based on a number of days. strRet += String::Format( headerFmt, "FromDays( 20.84745602 )", sNL ); strRet += ShowTimeSpanProperties( TimeSpan::FromDays( 20.84745602 ) ); return strRet; } |